home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: November 12 2000
- //
- // Procedure Name:
- // incrementalSaveScene
- //
- // Description:
- // Called when the scene is saved and the File->"Incremental Save"
- // menu item is checked "on".
- //
- // Performs a non-destructive save of the current scene by taking the
- // version of the scene that was last saved to disk and moving it to
- // a subdirectory for scene "increments". The subdirectory where
- // increments are moved to will be created if it doesn't exist.
- // Each scene has its own directory for increments.
- //
- // If a past increment is opened and then saved with Incremental Save on,
- // then it will become the newest version of the scene, and the scene that
- // was previously newest (the one outside of the increments directory)
- // will now become a past increment.
- //
- // For example, if scenes\myScene.mb already exists, and is modified,
- // then saving incrementally will cause the existing file to be moved into
- // scenes\myScene.mb.backup\myScene.0001.mb, and then scenes\myScene.mb would be
- // saved with the newest changes. If myScene.mb was subsequently saved again,
- // then the previous version would be moved to scenes\myScene.mb.backup\myScene.0002.mb
- //
- // If myScene.0001.mb was then opened, modified, and saved, then
- // scenes\myScene.mb would be moved to scenes\myScene.mb.backup\myScene.0003.mb
- // and the current changes would be saved over scenes\myScene.mb.
- // This is a means of reverting back to a previous version of a scene, while keeping
- // the changes that were made in the mean time.
- //
- // With this scheme, the latest increment of a scene will always be in the
- // original scene file location (scenes\myScene.mb, for example).
- //
- // NOTE: This procedure does not check for scene changes first; that is left
- // to the caller.
- //
- // Input Arguments:
- // None
- //
- // Return Value:
- // None.
- //
- global proc incrementalSaveScene()
- {
- string $scenePath = `file -q -sceneName`;
-
- string $pathInfo[] = incrementalSaveProcessPath( $scenePath );
- string $scenePath = $pathInfo[0];
- string $sceneName = $pathInfo[1];
- string $sceneExtension = $pathInfo[2];
- string $sceneNamePrefix = $pathInfo[3];
- string $currVersionString = $pathInfo[4];
- string $incrementDirName = $pathInfo[5];
-
-
- string $sceneToMove = $sceneNamePrefix + $sceneExtension;
- string $incrementDirPath = $scenePath + $incrementDirName;
-
- // Make sure we have a directory to back-up our previous version into.
- //
- if(!`file -q -exists $incrementDirPath`)
- sysFile -makeDir $incrementDirPath;
-
- $incrementDirPath = $incrementDirPath + "/";
-
- // Get the largest increment version for this scene from the increments directory.
- // Iterate through all the file names that match our scene name, keeping track of
- // the highest increment value found.
- //
- string $existingIncrements[];
- catch ( $existingIncrements = `getFileList
- -folder $incrementDirPath
- -filespec ($sceneNamePrefix + ".*" + $sceneExtension)` );
-
- $fileVersion = 0;
- int $thisVersion;
-
- for($i = 0; $i < size($existingIncrements); $i++) {
-
- string $noExtension = `substring $existingIncrements[$i]
- 1 (size($existingIncrements[$i]) - size($sceneExtension))`;
-
- $thisVersion = `match "[0-9]+$" $noExtension`;
-
- if($thisVersion > $fileVersion)
- $fileVersion = $thisVersion;
-
- }
-
- string $newVersionString = $fileVersion + 1;
-
- // Make the increment-number in the filename to be at least 4 digits in length.
- // Doing so makes sure that alphabetical ordering sorts the first 9999 increments.
- //
- int $i;
- for($i = size($newVersionString); $i < 4; $i++)
- $newVersionString = "0" + $newVersionString;
-
- // Build the name of the new scene
- //
- string $newSceneName = $sceneNamePrefix + "." + $newVersionString + $sceneExtension;
- string $newScenePath = $incrementDirPath + $newSceneName;
-
- // Check to make sure our script isn't going to overwrite an existing file
- // since this script should provide a non-destructive save. If this occurs,
- // it is an error in this script's logic (ack!).
- //
- if(`file -q -exists $newScenePath`)
- error ("Internal error in Incremental Save: should not be overwriting \""
- + $newSceneName + "\"! Bailing out without save.");
-
-
- // Check if this is read only and warn the user if necessary
- //
- string $pathToMove = ( $scenePath + $sceneToMove );
- if ( !`filetest -w $pathToMove` ) {
- // The original file is write protected
- //
- string $message = "Cannot save changes to read only file: " + $sceneToMove;
- confirmDialog -button "OK" -message $message;
- error $message;
- }
- // Copy the previous version into the incremental save directory
- //
- sysFile -move $newScenePath $pathToMove;
-
- // Save the new scene. We may be saving from a past increment, so make it
- // save over the original scene name (now that the previous one has been
- // backed up to the increments directory).
- //
- if(`file -q -sceneName` != ($scenePath + $sceneToMove)) {
- int $wasDefaultExtensions = `file -q -defaultExtensions`;
- file -defaultExtensions false;
- file -rename ($scenePath + $sceneToMove);
- file -defaultExtensions $wasDefaultExtensions;
- }
-
- // Print some useful information to the script editor so that users can
- // find out exactly what has been done
- //
- print ( "// Performing Incremental Save:\n" );
- print ( "// master file: " + $scenePath + $sceneToMove + "\n" );
- print ( "// increment file: " + $newScenePath + "\n" );
-
- evalEcho ("file -force -save -options \"v=0\"");
-
- // Now that we have made it this far, delete any old backups past the
- // number that the user has asked us to save
- //
-
- // Look up whether we are limiting the number of backups saved, and if so,
- // what the limit is
- //
- int $maxNumberBackups = -1;
- if ( ( `optionVar -exists incrementalSaveLimitBackups` ) &&
- ( `optionVar -exists incrementalSaveMaxBackups` ) )
- {
- if ( `optionVar -q incrementalSaveLimitBackups` ) {
- $maxNumberBackups = `optionVar -q incrementalSaveMaxBackups`;
- }
- }
- if ( $maxNumberBackups >= 0 ) {
- $existingIncrements = sort( $existingIncrements );
- // Figure out how many backups to delete. Adjust for the new backup that
- // we just created.
- //
- int $last = ( size( $existingIncrements ) + 1 ) - $maxNumberBackups;
- for ( $i = 0; $i < $last; $i++ ) {
- sysFile -delete ( $incrementDirPath + $existingIncrements[$i] );
- }
- }
- }
-